package xchain

import (
	"github.com/pkg/errors"
)

type ProcessChain[T any] struct {
	Name    string
	Error   error
	Result  *T
	Results []*T
}

func (p *ProcessChain[T]) Process(f func() (*T, error)) *ProcessChain[T] {
	if p.Error != nil {
		return p
	}

	res, err := f()
	if err != nil {
		p.Error = errors.Wrap(err, "Wrap Err in Process")
	} else if res != nil {
		p.Result = res
		p.Results = append(p.Results, res)
	}

	return p
}
